package com.taobao.job;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: caoling
 * Date: 11-3-11
 * Time: 11:27
 * To change this template use File | Settings | File Templates.
 */
public class TextDouble implements WritableComparable<TextDouble> {

    private String text;
    private Double score;

    private TextDouble() {
    }

    public TextDouble(String text, Double score) {
        this.text = text;
        this.score = score;
    }

    public String getText() {
        return this.text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Double getScore() {
        return this.score;
    }

    public void setScore(Double score) {
        this.score = score;
    }

    public int compareTo(TextDouble o) {
        if (o == null){
            return 1;
        }
        return this.text.compareTo(o.getText());
    }

    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(this.text);
        dataOutput.writeDouble(this.score.doubleValue());
    }

    public void readFields(DataInput dataInput) throws IOException {
        this.text = dataInput.readUTF();
        this.score = Double.valueOf(dataInput.readDouble());
    }
}
